home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Mod / Sec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  2.7 KB  |  130 lines

  1.  
  2. /*
  3.  
  4.     XDME seems to be nearly BugFree
  5.  
  6.     however, if there _is_ a bug left, and that Bug causes
  7.     the XDME Process freeze, this module is a possibility
  8.     to save the typed Data before resetting the machine ...
  9.  
  10.     We do define a possibility to access the Texts of one
  11.     XDME Process from another.
  12.  
  13.     Please note, that Function is incompatible to Virtual
  14.     Memory Mechanisms like e.g. VMM, since XDME allocates
  15.     its Texts as !MEMF_GLOBAL Memory.
  16.  
  17. */
  18.  
  19.  
  20. #include "defs.h"
  21.  
  22. #define MAGIC_NAME "Access_to_XDME_Texts"
  23.  
  24. static LIST *sec_dbase[1];
  25.  
  26.  
  27. DEFAUTOINIT( sec_init )
  28. {
  29. //puts (__FILE__);
  30.     sec_dbase[0] = &DBase;
  31.     SetVar(MAGIC_NAME, (void *)sec_dbase, sizeof(sec_dbase), LV_VAR | GVF_LOCAL_ONLY | GVF_BINARY_VAR);
  32. }
  33.  
  34. DEFAUTOEXIT( sec_exit )
  35. {
  36.     DeleteVar(MAGIC_NAME, LV_VAR | GVF_LOCAL_ONLY | GVF_BINARY_VAR);
  37. }
  38.  
  39. /* 1==port; 2==text; 3==file */
  40. DEFUSERCMD("foreignsave", 3, 0, void, do_foreignsave, (void), )
  41. {
  42.     struct MsgPort  *mp;
  43.     struct Process  *pr, *we;
  44.     struct LocalVar *lv;
  45.     UBYTE tc_state;
  46.     ED *ed;
  47.  
  48.     pr = we = (struct Process *)FindTask(NULL);
  49.  
  50.     Forbid();
  51.     mp = FindPort (av[1]);
  52.     if (!mp) {
  53.     Permit();
  54.     error ("%s:\nCan't find foreign Port `%s'!", av[0], av[1]);
  55.     return;
  56.     } /* if */
  57.  
  58.     if (mp->mp_Flags != PA_SIGNAL) {
  59.     Permit();
  60.     error ("%s:\nForeign Port `%s' \ndoes not signal a Task!", av[0], av[1]);
  61.     return;
  62.     } /* if */
  63.  
  64.     pr = mp->mp_SigTask;
  65.  
  66.     if (((struct Node *)pr)->ln_Type != NT_PROCESS) {
  67.     Permit();
  68.     error ("%s:\nForeign Port `%s' \ndoes not signal a DOS Process!", av[0], av[1]);
  69.     return;
  70.     } /* if */
  71.  
  72.     // ---- let the other process sleep
  73.     if (we != mp->mp_SigTask) {
  74.     tc_state = pr->pr_Task.tc_State;
  75.     pr->pr_Task.tc_State = TS_READY;
  76.     } /* if */
  77.  
  78.     Permit();
  79.  
  80.     for (lv = GetHead (&pr->pr_LocalVars); lv; lv = GetSucc(lv)) {
  81.     if ((lv->lv_Node.ln_Type != LV_VAR))
  82.         continue;
  83.     if (strcmp (lv->lv_Node.ln_Name, MAGIC_NAME) == 0)
  84.         break;
  85.     } /* for */
  86.  
  87.     if (!lv) {
  88.     error ("%s:\nForeign Port `%s' \ndoes not signal an accessible XDME Process!", av[0], av[1]);
  89.     goto sec_save_end;
  90.     } /* if */
  91.  
  92.     for (ed = GetHead ((struct MinList *)lv->lv_Value); ed; ed = GetSucc(ed)) {
  93.     if (stricmp(((struct Node *)ed)->ln_Name, av[2]) == 0) {
  94.         break;
  95.     } /* if */
  96.     } /* for */
  97.  
  98.     if (ed) {
  99.     UBYTE *iav[2];
  100.     BPTR our_dl;
  101.     ED *our_ep;
  102.  
  103.     our_ep = Ep;
  104.     Ep     = ed;
  105.  
  106.     iav[0] = av[0];
  107.     av[0]  = "writeto";
  108.  
  109.     iav[1] = av[1];
  110.     av[1]  = av[3];
  111.  
  112.     our_dl = CurrentDir(Ep->dirlock);
  113.  
  114.     do_writeto();
  115.  
  116.     Ep->dirlock = CurrentDir(our_dl);
  117.     av[0]        = iav[0];
  118.     av[1]        = iav[1];
  119.     Ep        = our_ep;
  120.     } /* if */
  121.  
  122. sec_save_end:
  123.     if (we != pr) {
  124.     Forbid();
  125.     pr->pr_Task.tc_State = tc_state;
  126.     Permit();
  127.     } /* if */
  128. }
  129.  
  130.